package com.sunny.blog.common.config;

import cn.hutool.json.JSONUtil;
import com.sunny.blog.common.entity.SysConstant;
import com.sunny.blog.pojo.SysLog;
import com.sunny.blog.service.ISysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @ClassName: SysLogListener
 * @Description:
 * @Author: sunt
 * @Date: 2020/5/22 16:11
 * @Version 1.0
 **/
@Component
@EnableRabbit
@Configuration
@Slf4j
public class SysLogReceiveListener {

    @Autowired
    private ISysLogService sysLogService;

    @RabbitListener(queues = SysConstant.SYS_LOG_RECEIVE_QUEUE)
    @RabbitHandler
    public void receiveSysLog(String msg) {
        log.info("----------->接收日志消息:" + msg);
        SysLog sysLog = JSONUtil.toBean(msg, SysLog.class);
        sysLogService.insertSysLog(sysLog);

    }
}
